package com.zggk.iroad.handle.handlemx;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zggk.iroad.R;
import com.zggk.iroad.adapter.recycleview.LGRecycleViewAdapter;
import com.zggk.iroad.adapter.recycleview.LGViewHolder;
import com.zggk.iroad.mvp.MVPBaseActivity;
import com.zggk.iroad.util.MyUtils;
import com.zggk.iroad.util.NoScroolGridView;
import com.zggk.iroad.util.NoScroolRecycle;
import com.zggk.iroad.util.ShowGridAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class HandleMxActivity extends MVPBaseActivity<HandleMxContract.View, HandleMxPresenter> implements HandleMxContract.View {


    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.cancle_button)
    TextView cancleButton;
    @Bind(R.id.cjdw_ed)
    TextView cjdwEd;
    @Bind(R.id.cjdw_lay)
    LinearLayout cjdwLay;
    @Bind(R.id.sgdw_ed)
    TextView sgdwEd;
    @Bind(R.id.sgdw_lay)
    LinearLayout sgdwLay;
    @Bind(R.id.szh_k)
    TextView szhK;
    @Bind(R.id.szh_lay)
    LinearLayout szhLay;
    @Bind(R.id.wzh_k)
    TextView wzhK;
    @Bind(R.id.wzh_lay)
    LinearLayout wzhLay;
    @Bind(R.id.disease_shang_txt)
    TextView diseaseShangTxt;
    @Bind(R.id.xsfx_lay)
    LinearLayout xsfxLay;
    @Bind(R.id.bz_lay)
    LinearLayout bzLay;
    @Bind(R.id.bz_et)
    TextView bzEt;
    @Bind(R.id.bhmc_ed)
    TextView bhmcEd;
    @Bind(R.id.bhmc_lay)
    LinearLayout bhmcLay;
    @Bind(R.id.bhsl_te)
    TextView bhslTe;
    @Bind(R.id.dw_te)
    TextView dwTe;
    @Bind(R.id.bhsl_lay)
    LinearLayout bhslLay;
    @Bind(R.id.wxcc_te)
    TextView wxccTe;
    @Bind(R.id.wxcc2_te)
    TextView wxcc2Te;
    @Bind(R.id.wxcc3_te)
    TextView wxcc3Te;
    @Bind(R.id.wxcc_lay)
    LinearLayout wxccLay;
    @Bind(R.id.sgfs_ed)
    TextView sgfsEd;
    @Bind(R.id.sgfs_lay)
    LinearLayout sgfsLay;
    @Bind(R.id.czfa_re)
    NoScroolRecycle czfaRe;
    @Bind(R.id.bz2_et)
    TextView bz2Et;
    @Bind(R.id.cjtp_lay)
    LinearLayout cjtpLay;
    @Bind(R.id.cjtp_ig)
    ImageView cjtpIg;
    @Bind(R.id.tjtp_lay)
    LinearLayout tjtpLay;
    @Bind(R.id.add_pic_grid)
    NoScroolGridView addPicGrid;
    @Bind(R.id.add_pic_lay)
    LinearLayout addPicLay;
    @Bind(R.id.cjd_lay)
    ScrollView cjdLay;
    private LGRecycleViewAdapter<HandleMxBean.SGCZFABean> adapter;
    private List<HandleMxBean.SGCZFABean> Datas = new ArrayList<>();

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_handle_mx;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        initAdapter();
        initData();
        initView();
    }

    private void initData() {
        mPresenter.testinfo(HandleMxActivity.this, getIntent().getStringExtra("RZID"));
    }

    private void initView() {
        titleText.setText("施工维修");
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void getData(HandleMxBean videoVos2) {
        if (videoVos2.getBHDATA() != null && videoVos2.getBHDATA().size() > 0) {
            cjdwEd.setText(videoVos2.getBHDATA().get(0).getGYDW());
            sgdwEd.setText(videoVos2.getBHDATA().get(0).getSGDW());

            szhK.setText(MyUtils.getZHMCByZH(videoVos2.getBHDATA().get(0).getQDZH()));
            wzhK.setText(MyUtils.getZHMCByZH(videoVos2.getBHDATA().get(0).getQDZHWX()));
            diseaseShangTxt.setText(videoVos2.getBHDATA().get(0).getWZFX());
            bzEt.setText(videoVos2.getBHDATA().get(0).getBZ());

            bhmcEd.setText(videoVos2.getBHDATA().get(0).getBHLX());
            sgfsEd.setText(videoVos2.getBHDATA().get(0).getCZFAMC());
            if (videoVos2.getSGCZFA() != null && videoVos2.getSGCZFA().size() > 0) {
                Datas.addAll(videoVos2.getSGCZFA());
                adapter.notifyDataSetChanged();
            }
            if (videoVos2.getCJTP() != null && videoVos2.getCJTP().size() > 0) {
                Glide.with(HandleMxActivity.this)
                        .load(videoVos2.getCJTP().get(0).getFILEPATH())
                        .into(cjtpIg);
            }
            ArrayList<String> listImgUrl = new ArrayList<>();
            if (videoVos2.getSGQTP() != null) {
                listImgUrl.add(videoVos2.getSGQTP());
            }
            if (videoVos2.getSGZTP() != null) {
                listImgUrl.add(videoVos2.getSGZTP());
            }
            if (videoVos2.getSGHTP() != null) {
                listImgUrl.add(videoVos2.getSGHTP());
            }
            ShowGridAdapter showGridAdapter = new ShowGridAdapter(this, listImgUrl);
            addPicGrid.setAdapter(showGridAdapter);
        }

    }

    private void initAdapter() {
        LinearLayoutManager manager = new LinearLayoutManager(HandleMxActivity.this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        czfaRe.setLayoutManager(manager);
        czfaRe.setHasFixedSize(true);
        czfaRe.setNestedScrollingEnabled(false);
        adapter = new LGRecycleViewAdapter<HandleMxBean.SGCZFABean>(Datas) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_handle_czfa;
            }

            @Override
            public void convert(LGViewHolder holder, HandleMxBean.SGCZFABean zCDBean, int position) {
                holder.setText(R.id.name_te, zCDBean.getGCXM());
                holder.setText(R.id.sl_te, zCDBean.getJSGS());
                holder.setText(R.id.dw_te, zCDBean.getSL() + " " + zCDBean.getDW());
            }
        };

        czfaRe.setAdapter(adapter);
    }
}
